#include "main.h"
#include "gpio.h"


#define OLED_ENABLE 0


unsigned char bMS1Chg,bMS10Chg,bMS100Chg,bSecChg;
unsigned int HOUR,MIN,SEC;
unsigned int MS1,MS10,MS100,Sec;

void Clock_Init()
{
	MS1=10;
	MS10=10;
	MS100=10;
	Sec=60;
	bSecChg=0;
	bMS100Chg=0;
	bMS10Chg=0;
	bMS1Chg=0;


}

void Clock_Cnt()
{
	bMS1Chg=1;
	if (--MS1) return;
	MS1=10;
	
	bMS10Chg=1;
	if (--MS10) return;
	MS10=10;

	bMS100Chg=1;
	if (--MS100) return;
	MS100=10;

	bSecChg=1;
	SEC++;
	if(SEC==60) {SEC = 0;MIN++;}
	if(MIN==60) {MIN = 0;HOUR++;}
	
	if (--Sec) return;
	Sec=60; 
	
}

#if OLED_ENABLE

#include "XMF_OLED.h"
void OLED_ShowClock(unsigned int x,unsigned int y)
{
	OLED_ShowNum(x,y,HOUR/10,1,8);	
	OLED_ShowNum(x+8,y,HOUR%10,1,8);
	OLED_ShowNum(x+24,y,MIN/10,1,8);	
	OLED_ShowNum(x+32,y,MIN%10,1,8);
	OLED_ShowNum(x+48,y,SEC/10,1,8);	
	OLED_ShowNum(x+56,y,SEC%10,1,8);
	if(SEC%2==0)
	{
		OLED_ShowChar(x+16,y,':');
		OLED_ShowChar(x+40,y,':');
	}
	else
	{
		OLED_ShowChar(x+16,y,' ');
		OLED_ShowChar(x+40,y,' ');
	}
	
}

#endif

